/**
 * 
 */
package xiaojian.toolkit.fsm;

import xiaojian.toolkit.ebus.EventBus;

/**
 * @author hp
 *
 */
public class DefaultFSMContextFactory implements FSMContextFactory {

	private	String		initStateName;
	private	EventBus	eventBus;
	
	/**
	 * @return the eventBus
	 */
	public EventBus getEventBus() {
		return eventBus;
	}

	/**
	 * @param eventBus the eventBus to set
	 */
	public void setEventBus(EventBus eventBus) {
		this.eventBus = eventBus;
	}

	/* (non-Javadoc)
	 * @see com.skymobi.fsm.FSMContextFactory#createFSMContext(java.lang.Object)
	 */
	public MutableFSMContext createFSMContext(FiniteStateMachine fsm, Object event) {
		DefaultFSMContext ctx = new DefaultFSMContext(fsm);
		
		ctx.setCurrentState(initStateName);
		ctx.setEventBus(eventBus);
		return ctx;
	}

	public String getInitStateName() {
		return initStateName;
	}

	public void setInitStateName(String initStateName) {
		this.initStateName = initStateName;
	}

	public void setInitState(State state) {
		this.initStateName = FSMUtils.getStateNameOfInstance(state);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "DefaultFSMContextFactory [initStateName=" + initStateName + "]";
	}
}
